package com.payment.web.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.common.base.AjaxResult;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.CompanyMoneyChang;
import com.payment.system.service.ICompanyMoneyChangService;

/**
 * 公司入账记录 信息操作处理
 *
 * @author payment
 * @date 2019-12-03
 */
@Controller
@RequestMapping("/system/companyMoneyChang")
public class CompanyMoneyChangController extends BaseController {
    private String prefix = "system/companyMoneyChang";

    @Autowired
    private ICompanyMoneyChangService companyMoneyChangService;

    @RequiresPermissions("system:companyMoneyChang:view")
    @GetMapping()
    public String companyMoneyChang() {
        return prefix + "/companyMoneyChang";
    }

    /**
     * 查询公司入账记录列表
     */
    @RequiresPermissions("system:companyMoneyChang:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyMoneyChang companyMoneyChang) {
        startPage();
        List<CompanyMoneyChang> list = companyMoneyChangService.selectCompanyMoneyChangList(companyMoneyChang);
        //获取总笔数和总交易额
        Map<String, Object> money = companyMoneyChangService.selectCompanyMoneyChangTotalMoney(companyMoneyChang);
        if (list != null && list.size() > 0) {
            list.get(0).setNumber(Integer.parseInt(money.get("number").toString()));
            list.get(0).setTotalEntryMoney(new BigDecimal((money.get("totalEntryMoney").toString())));
            list.get(0).setTotalProfitMoney(new BigDecimal((money.get("totalProfitMoney").toString())));
            list.get(0).setTotalMoney(new BigDecimal((money.get("totalMoney").toString())));
        }

        return getDataTable(list);
    }


    /**
     * 导出公司入账记录列表
     */
    @RequiresPermissions("system:companyMoneyChang:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyMoneyChang companyMoneyChang) {
        List<CompanyMoneyChang> list = companyMoneyChangService.selectCompanyMoneyChangList(companyMoneyChang);
        ExcelUtil<CompanyMoneyChang> util = new ExcelUtil<CompanyMoneyChang>(CompanyMoneyChang.class);
        return util.exportExcel(list, "companyMoneyChang");
    }


}
